package com.yongcheon.starhealthcare.friend.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.facebook.Request;
import com.facebook.Response;
import com.facebook.model.GraphUser;
import com.yongcheon.starhealthcare.R;
import com.yongcheon.starhealthcare.facebook.FacebookCallback;
import com.yongcheon.starhealthcare.friend.list.FriendsListAdapter;

import java.util.List;

/**
 * Created by yongcheon on 2015-02-06.
 */
public class FriendsFragment extends Fragment {
    View linear;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View linear = inflater.inflate(R.layout.friend_friends_list, container, false);
        this.linear = linear;
        requestFriend();
        return linear;
    }

    private void requestFriend(){
        Request request = Request.newMyFriendsRequest(FacebookCallback.session, new CustomFaceBookCallback());
        Bundle params = new Bundle();
        params.putString("fields", "id,name,picture,first_name,last_name,birthday");
        request.setParameters(params);
        request.executeAsync();
    }


    class CustomFaceBookCallback implements Request.GraphUserListCallback {
        @Override
        public void onCompleted(List<GraphUser> graphUsers, Response response) {
            ListView listView = (ListView)linear.findViewById(R.id.friendlist);
            FriendsListAdapter friendsListAdapter = new FriendsListAdapter(FriendsFragment.this.getActivity(),graphUsers);
            listView.setAdapter(friendsListAdapter);
        }
    }
}
